#include "tq.h"
#include <cjson/cJSON.h>
cJSON* json_get(cJSON* root, const char* path) {
    char* copy = strdup(path);
    char* token = strtok(copy, ".");
    cJSON* current = root;
    
    while (token && current) {
        current = cJSON_GetObjectItemCaseSensitive(current, token);
        token = strtok(NULL, ".");
    }
    
    free(copy);
    return current;
}
int main() {
    tq* ts = tq_init(NULL);
    
    // 获取天气数据
    cJSON* weather = tq_dwtq(ts);
    if (weather) {

        cJSON* img = json_get(weather, "data.real.weather.img");
        printf("%s\n", img->valuestring);
        if (img && cJSON_IsString(img)) {
            char filename[256];  // 假设文件名不会超过这个长度
            snprintf(filename, sizeof(filename), "%s.png", img->valuestring);
            tq_down_png(ts, filename);
        }
        char* printed = cJSON_Print(weather);
        printf("%s\n", printed);
        free(printed);
        cJSON_Delete(weather);
    }
    
    // 下载并缩放图标
    
    
    tq_free(ts);
    return 0;
}